import './assert/style.css'
import ControlledDom from './ControlledDom'
import Slider from './Slider'
import {createMapNode} from './dom'
import initEdit from './initEdit'
import {appendNode} from './vnode'
import { isELementNode , createError, getDom} from './util';


window.addEventListener('DOMContentLoaded', () => {
    let easy = new EasyMindMap('.emm-wrap')
    easy.init('欢迎使用')

}, false)


class EasyMindMap{
    constructor(wrapper, options = {}){
        wrapper = getDom(wrapper)

        if (!isELementNode(wrapper)) throw createError(EasyMindMap, 'first param need element')

        this.wrapper = wrapper
        this.stage = options.stage ? getDom(options.stage) :  wrapper.firstElementChild
    }

    init(msg, posx = 50, posy = 50){
        this.rootNode = createMapNode(msg, posx, posy)
        appendNode(this.stage, this.rootNode)
        initEdit(this.stage, this.rootNode)

        let cdom = this.cdom = new ControlledDom(this.stage, {
            listenerDom: this.wrapper
        })
        this.cdom.init()
    
        this.slider = new Slider(this.wrapper, {
            onSlide(proggress){
                proggress = (proggress + 50) / 100
                cdom.setScale(proggress)
            }
        })
        this.slider.init()
    }    
}


